package com.admin4j.server.system.controller;

import com.admin4j.framework.web.pojo.R;
import com.admin4j.server.system.entity.SysMenu;
import com.admin4j.server.system.entity.vo.MenuVO;
import com.admin4j.server.system.service.ISysMenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author andanyang
 * @since 2023-11-14
 */
@RestController
@RequestMapping("/system/menu")
public class SysMenuController {

    @Autowired
    ISysMenuService sysMenuService;

    @GetMapping("allTree")
    @ApiOperation("菜单树")
    public R<List<MenuVO>> allTree() {

        return R.ok(sysMenuService.allTree());
    }

    @PostMapping
    @ApiOperation("添加菜单")
    public R add(@RequestBody SysMenu menu) {

        sysMenuService.save(menu);
        return R.ok();
    }

    @PutMapping
    @ApiOperation("编辑菜单")
    public R edit(@RequestBody SysMenu menu) {

        sysMenuService.updateById(menu);
        return R.ok();
    }
}
